package com.eastfair.imaster.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.imaster.dto.ConferenceSpeakerPageQuery;
import com.eastfair.imaster.dto.ConferenceSpeakerSaveDTO;
import com.eastfair.imaster.dto.ConferenceSpeakerUpdateDTO;
import com.eastfair.imaster.entity.ConferenceSpeaker;
import com.eastfair.imaster.service.ConferenceSpeakerService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 论坛嘉宾
 * </p>
 *
 * @author zjn
 * @date 2021-08-31
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/conferenceSpeaker")
@Api(value = "ConferenceSpeaker", tags = "论坛嘉宾")
public class ConferenceSpeakerController extends SuperController<ConferenceSpeakerService, Long, ConferenceSpeaker, ConferenceSpeakerPageQuery, ConferenceSpeakerSaveDTO, ConferenceSpeakerUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private ConferenceSpeakerService conferenceSpeakerService;

    @Override
    public void handlerResult(IPage<ConferenceSpeaker> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<ConferenceSpeaker> conferenceSpeakerList = list.stream().map((map) -> {
            ConferenceSpeaker conferenceSpeaker = ConferenceSpeaker.builder().build();
            //TODO 请在这里完成转换
            return conferenceSpeaker;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(conferenceSpeakerList));
    }

}
